package com.yupi.project.controller;


import com.yupi.project.common.BaseResponse;
import com.yupi.project.common.ResultUtils;
import com.yupi.project.model.dto.student.VideoDto;
import com.yupi.project.model.entity.User;
import com.yupi.project.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/student")
public class MyStudentController {
    @Resource
    private UserService userService;

    @RequestMapping("/selectAll")
    public BaseResponse selectAll() {
        return ResultUtils.success(userService.list());
    }

    /**
     * 插入调查问卷到我们的数据库中去(全部都是普通字段)
     *
     * @param user
     * @return
     */
    @PostMapping("/insertQuestion")
    private BaseResponse insertQuestion(User user) {
        //
        boolean save = userService.save(user);
        return ResultUtils.success(save);
    }

    /**
     * 上传我们的视频/图片封面和我们的视频的基本信息
     *
     * @param user
     * @param file
     * @param image
     * @return
     */
    @PostMapping("/addVideo")
    private BaseResponse addVideo(VideoDto user,
                                  @RequestParam("file") MultipartFile file,
                                  @RequestParam("image") MultipartFile image) {
        return userService.addVideo(user, file, image);
    }
}
